import { FC } from 'react'
import { Routes, Route, Navigate, useLocation  } from 'react-router-dom'

import Index from './layout/Index'
import { useAppSelector } from "./store/hooks";
import {Index as Login} from './views/login/Index'

const App = (props) => {
  const loginState = localStorage.getItem('adminname')
  
  const {search} = useLocation() 
  const redirectUrl = search.split('?r=')[1] 
  const str = redirectUrl ? redirectUrl : '/'
  return(
  // 路由出口
  <Routes>
    <Route path="/login" element = { loginState ? <Navigate to={str} /> : <Login /> }/>
    <Route path="/*" element = { loginState ? <Index /> : <Navigate to="/login" /> } />
  </Routes>
)};

export default App;
